package com.comm.utils.date;

import java.util.Calendar;
import java.util.Date;

/**
 *  日期工具类
 */
public class DateUtils {

    /**
     * 获取2个日期之间间隔的天数
     * 是否有更简便的方法
     * @param startDate 起始日期
     * @param endDate   终止日期
     * @return
     */
    public static int getDateIntervalDays(Date startDate, Date endDate){
        int interval=0;
        if(startDate!=null && endDate!=null){
            Calendar startCalendar= Calendar.getInstance();
            startCalendar.setTime(startDate);
            //将时分秒和毫秒置为0
            startCalendar.set(Calendar.HOUR_OF_DAY,0);
            startCalendar.set(Calendar.MINUTE,0);
            startCalendar.set(Calendar.SECOND,0);
            startCalendar.set(Calendar.MILLISECOND,0);
            Calendar endCalendar=Calendar.getInstance();
            endCalendar.setTime(endDate);
            //将时分秒和毫秒置为0
            endCalendar.set(Calendar.HOUR_OF_DAY,0);
            endCalendar.set(Calendar.MINUTE,0);
            endCalendar.set(Calendar.SECOND,0);
            endCalendar.set(Calendar.MILLISECOND,0);
            long timeInterval=(endCalendar.getTime().getTime()-startCalendar.getTime().getTime())/(1000 * 60 * 60 * 24);
            interval=Integer.parseInt(String.valueOf(timeInterval));
        }
        return interval;
    }


}
